package gamesys.games.particlesystem {
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;

	public class AbstractTest extends Sprite {

		private var assetQueue : Number;

		public function AbstractTest() {
			assetQueue = 0;
			loadAssets();
		}

		protected function loadAssets() : void {
			loadViaLoader("../particle-system/assets/Particles.swf");
		}

		protected function loadViaLoader(url : String) : void {
			var request : URLRequest = new URLRequest(url);
			var loader : Loader = new Loader();
			
			assetQueue++;
			
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGraphicalLoadComplete);
			loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			
			loader.load(request, new LoaderContext(false, ApplicationDomain.currentDomain));
		}

		private function onGraphicalLoadComplete(event : Event) : void {
			onAssetLoaded();
		}

		private function onAssetLoaded() : void {
			assetQueue--;
			if(assetQueue == 0) {
				init();
			}
		}

		protected function init() : void {
			trace("init should be overriden");
		}

		private function onIOError(event : IOErrorEvent) : void {
			trace("onIOError", event.text);
		}

		private function onSecurityError(event : SecurityErrorEvent) : void {
			trace("onSecurityError");
		}
	}
}
